#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/shm.h>
#include <stdlib.h>
#include <sys/ipc.h>
#include <unistd.h>
int main()
{
	key_t k = ftok(".",0x11);
	if(k == -1)
	{
		perror("ftok");
		exit(1);
	}
	printf("0x%x\n",k);
	int shmid = shmget(k,4096,IPC_CREAT | IPC_EXCL | 0666);
	if(shmid == -1)
	{
		perror("shmget");
		exit(1);
	}
	char* ptr = shmat(shmid,NULL,0);
	if(ptr == (char*)-1)
	{
		perror("shmat");
		exit(1);
	}
	strcpy(ptr,"i am process A\n");
	int dt = shmdt(ptr);
	if(dt == -1)
	{
		perror("shmdt");
		exit(1);
	}

  //  if (shmctl(shmid, IPC_RMID, NULL) == -1)
  //  { 
  //      perror("shmctl");
  //      exit(1);
  //  }

	return 0;
}
